package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.pojo.Banner;
import org.example.pojo.Query;
import org.example.service.BannerService;
import org.example.mapper.BannerMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 13326
* @description 针对表【hards_banner】的数据库操作Service实现
* @createDate 2025-01-05 10:14:01
*/
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner>
    implements BannerService{
    @Resource
    private BannerMapper bannerMapper;
    @Override
    public Result getlist(Query query){
        IPage<Banner> page=new Page<>(query.getPageNum(), query.getPageSize());
       bannerMapper.selectPageMap(page,query);
        HashMap<String,Object> hashMap=new HashMap<>();
        hashMap.put("total",page.getTotal());
        hashMap.put("rows",page.getRecords());
        hashMap.put("pages",page.getPages());
        hashMap.put("size",page.getSize());
        return Result.ok(hashMap);

    }
    @Override
    public Result add(Banner banner){
        bannerMapper.insert(banner);
        return Result.ok("新增成功");
    }
    @Override
    public Result updatebanner(Banner banner){
        bannerMapper.updateById(banner);
        return Result.ok("修改成功");
    }
    @Override
    public Result delete(Integer id){
        bannerMapper.deleteById(id);
        return Result.ok("删除成功");
    }
    @Override
    public Result getall(){
        LambdaQueryWrapper<Banner> lambdaQueryWrapper=new LambdaQueryWrapper<>();
       List<Banner> list= bannerMapper.selectList(lambdaQueryWrapper);
        return  Result.ok(list);
    }


}




